package com.yssoft.service.special;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yssoft.entity.special.TsQualificationProofEntity;
import com.yssoft.entity.special.TsSuspensionResumptionEntity;
import com.yssoft.mapper.special.TsQualificationProofMapper;
import com.yssoft.utils.UploadFile;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;
import java.util.List;
import java.util.Arrays;
import java.util.UUID;

/**
 * 资质证明Service接口
 * @author: ZhouZhou
 * @date 2025-07-26 18:05:19
 */
@Service
public class TsQualificationProofService extends ServiceImpl<TsQualificationProofMapper, TsQualificationProofEntity> {

	@Resource
	private TsQualificationProofMapper tsQualificationProofMapper;

	/**
	 * mybaitis-plus 单表页面分页查询
     */
	/*public PageUtil findPage(Map<String, Object> params) {
		QueryWrapper<TsQualificationProofEntity> queryWrapper = new QueryWrapper<TsQualificationProofEntity>();
		String companyId = (String) params.get("companyId");
		String deleteFlag = (String) params.get("deleteFlag");
		String nameOfQualification = (String) params.get("nameOfQualification");
		String firstDate = (String) params.get("firstDate");
		String thisDate = (String) params.get("thisDate");
		String endDate = (String) params.get("endDate");
		String fileUrl = (String) params.get("fileUrl");
		String deleteTime = (String) params.get("deleteTime");
		String createId = (String) params.get("createId");
		String updateId = (String) params.get("updateId");
		String deleteId = (String) params.get("deleteId");
		Page<TsQualificationProofEntity> page = tsQualificationProofMapper.selectPage(new Query<TsQualificationProofEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }*/

	/**
	 * 自定义分页查询，含关联实体对像
	 */
	/*public PageUtil findPage(Map<String, Object> params,TsQualificationProofEntity tsQualificationProofEntity) {
		params.put("__limit", "10000");
		params.put("__page", "0");
		tsQualificationProofEntity.setCompanyId(Long.parseLong(tsQualificationProofEntity.getId()));

		Page<TsQualificationProofEntity> page = tsQualificationProofMapper.findPage(new Query<TsQualificationProofEntity>(params).getPage(),
					tsQualificationProofEntity,
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}*/

	/**
	* 查列表
	*/
	public List<TsQualificationProofEntity> findList(TsQualificationProofEntity tsQualificationProofEntity){
		return tsQualificationProofMapper.findList(tsQualificationProofEntity);
	}

	/**
     * 批量删除
     *//*
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteBatchByIds(Long[] ids) {
		return this.removeByIds(Arrays.asList(ids));
	}

	*//**
     * 单个删除
     *//*
	@Transactional(rollbackFor = Exception.class)
	public boolean delTsQualificationProofById(String id) {
		return this.removeById(id);
	}

	*//**
     * 保存
     *//*
	@Transactional(rollbackFor = Exception.class)
	public boolean addTsQualificationProof(TsQualificationProofEntity tsQualificationProof){
		tsQualificationProof.setId(UUID.randomUUID().toString().replaceAll("-", ""));
*//*		LoginUserEntity loginUser = UserUtils.getUserInfo();

		tsQualificationProof.setCreateBy(loginUser.getId().toString());
*//*
		if(this.save(tsQualificationProof)){
			return true;
		}
        return false;
    }

	*//**
     * 修改根居ID
     *//*
	@Transactional(rollbackFor = Exception.class)
	public boolean updateTsQualificationProofById(TsQualificationProofEntity tsQualificationProof) {
		if(this.updateById(tsQualificationProof)){
			return true;
		}
		return false;
	}

	*//**
     * 根居ID获取对象
     *//*
	public TsQualificationProofEntity findTsQualificationProofById(String id){
		return tsQualificationProofMapper.findTsQualificationProofById(id);
	}

	*//**
	 * 软删除
	 *//*
	@Transactional(rollbackFor = Exception.class)
	public boolean delete(TsQualificationProofEntity entity) {
		LambdaUpdateWrapper<TsQualificationProofEntity> wrapper = new LambdaUpdateWrapper<>();
		wrapper.eq(TsQualificationProofEntity::getId, entity.getId()) // 根据 id 匹配
				.set(TsQualificationProofEntity::getDeleteFlag, "1"); // 设置 deleteId 的值

		return this.update(wrapper);
	}*/

	/**
	 * 保存
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean addTsQualificationProof(TsQualificationProofEntity entity, MultipartFile file){
		entity.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		if(file.getOriginalFilename().length()>0){
			Map<String, Object> urlMap = UploadFile.compressUploadedFile(file);
			entity.setFileUrl(urlMap.get("fileName")+"");
			entity.setFileUrl(urlMap.get("thumbnails")+"");
		}
		if(this.save(entity)){
			return true;
		}
		return false;
	}

	/**
	 * 修改根居ID
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean update(TsQualificationProofEntity entity, MultipartFile file) {
		if(file.getOriginalFilename().length()>0){
			Map<String, Object> urlMap = UploadFile.compressUploadedFile(file);
			entity.setFileUrl(urlMap.get("fileName")+"");
			entity.setFileUrl(urlMap.get("thumbnails")+"");
		}
		if(this.updateById(entity)){
			return true;
		}
		return false;
	}

	/**
	 * 软删除
	 */
	@Transactional(rollbackFor = Exception.class)
	public boolean delete(TsQualificationProofEntity entity) {
		entity.setDeleteFlag(1);
		return this.updateById(entity);
	}
}
